// Created by Xslt generator for Eclipse.
// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.ba360.struts.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ba360.portal.categories.CategoryList;
import com.ba360.portal.categories.MainCat;
import com.ba360.portal.database.DBConnectionImpl;
import com.ba360.portal.util.Log;

/**
 * Action.java created by EasyStruts - XsltGen. http://easystruts.sf.net created
 * on 03-30-2004
 * 
 * XDoclet definition:
 * 
 * @struts:action validate="true"
 * @struts:action-forward name="/jsp/CategoryBrowser.jsp"
 *                        path="/jsp/CategoryBrowser.jsp" contextRelative="true"
 */
public class YellowPageAction extends Action {

	// --------------------------------------------------------- Instance
	// Variables

	// --------------------------------------------------------- Methods

	/**
	 * Method execute
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param ActionForm
	 *            form
	 * @param HttpServletRequest
	 *            request
	 * @param HttpServletResponse
	 *            response
	 * @return ActionForward
	 * @throws Exception
	 */
	public static String SUCCESS = "success";

	public static String FAILURE = "failure";

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();

		if (session.getAttribute("YPLIST") == null) {
			Log.info("YPAction");

			DBConnectionImpl dbConn = new DBConnectionImpl();
			Connection conn = dbConn.getConnection();
			Statement stmt = conn.createStatement();
			//ResultSet rs = stmt.executeQuery("select category_id,name from
			// categories_yp where par_category_id is null");
			ResultSet rs = stmt
					.executeQuery("select distinct(city) from items_yp");
			MainCat[] mainCat = new MainCat[11];
			Log.init(this.getClass());
			Log.info("Fetch Size:" + rs.getFetchSize());
			int count = 0;
			ArrayList catList = new ArrayList();

			while (rs.next()) {
				String name = rs.getString(1);
				CategoryList cn = new CategoryList();
				Log.info(name);
				cn.setCategoryName(name);
				catList.add(cn);
				/*
				 * Statement stmt1 = conn.createStatement(); String mainCatName =
				 * rs.getString("name"); int mainCatId =
				 * rs.getInt("category_id");
				 * 
				 * ResultSet rs1 = stmt1.executeQuery("select category_id,name
				 * from categories_yp where
				 * par_category_id="+rs.getInt("category_id")); ArrayList subCat =
				 * new ArrayList(); while (rs1.next()) { String subCatName =
				 * rs1.getString("name"); int subCatId =
				 * rs1.getInt("category_id");
				 * 
				 * SubCatList subCatList = new SubCatList(subCatName, subCatId);
				 * 
				 * subCat.add(subCatList); } rs1.close(); MainCat mainCatTemp =
				 * new MainCat(mainCatName,subCat);
				 * mainCatTemp.setMainCatId(mainCatId); mainCat[count] =
				 * mainCatTemp; count = count+1;
				 * 
				 * catList.add(mainCat);
				 */
			}
			rs.close();
			/*
			 * rs= stmt.executeQuery("select name,category_id from
			 * categories_yp"); Hashtable categories= new Hashtable(); Hashtable
			 * categoryIds = new Hashtable(); while (rs.next()) { int mainCatId =
			 * rs.getInt("category_id"); String catName = rs.getString("name");
			 * 
			 * categories.put(mainCatId+"",catName); } rs.close();
			 * 
			 * rs = stmt.executeQuery("select category_id,par_category_id from
			 * categories_yp"); while (rs.next()) { int catId =
			 * rs.getInt("category_id"); int parentCatId =
			 * rs.getInt("par_category_id");
			 * 
			 * categoryIds.put(catId+"",parentCatId+""); } rs.close();
			 * 
			 * 
			 * 
			 * //session.setAttribute("ALLCATEGORY",categories);
			 * //session.setAttribute("CATIDS",categoryIds); TestList tl = new
			 * TestList(mainCat);
			 */

			session.setAttribute("YPLIST", catList);//tl);//catList);

			stmt.close();
			conn.close();
		}
		return mapping.findForward(SUCCESS);
		//throw new UnsupportedOperationException("Generated method
		// 'execute(...)' not implemented.");
	}

	class CityNames {
		String name;

		public void setName(String name) {
			this.name = name;
		}

		public String getName() {
			return name;
		}
	}

}